package hopital.orm;

import hopital.sql.SqlObject;
import hopital.sql.SqlQuery;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class DetailFacture extends SqlObject{
    
    
    private int _facture ;
    private String _service;
    private double _prix;

    DetailFacture(int _id) {
        this._facture=_id;
    }



    
    public int getDocteur() {
        return _facture;
    }



    public DetailFacture(int _facture,double _prix , String _service) {
        this._facture = _facture;
        this._service = _service;
        this._prix = _prix;
    }

   


    

    public DetailFacture() {
    }

    
    
    private DetailFacture(ResultSet _rs) throws SQLException {
       this(_rs.getInt("c_facture"), _rs.getInt("c_prix"), _rs.getString("c_service"));
       this._id=_rs.getInt("c_facture");
    }
    
    @Override
    public SqlQuery insert() {
        return new SqlQuery("INSERT INTO t_detail_factures (c_facture,c_prix,c_service) VALUES(?,?,?);",_facture,_prix,_service);
    }

    @Override
    public SqlQuery update() {
        return new SqlQuery("UPDATE t_detail_factures SET c_prix=? WHERE c_facture=? AND c_service=?;",_prix,_facture,_service);
    }

    @Override
    public SqlQuery delete() {
        return new SqlQuery("DELETE FROM t_detail_factures WHERE c_facture=?;", _facture);
    }

    @Override
    public SqlQuery select() {
            return new SqlQuery("SELECT * FROM t_detail_factures WHERE c_facture=?;", _facture);
    }

    @Override
    public List<Object> getTable(ResultSet _rs) throws Exception {
        List<Object> list=new ArrayList<>();
        while (_rs.next()) {            
            list.add(new DetailFacture(_rs));
        }
        return list;
    }
}
